package com.yiqi.news.app.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.scwang.smartrefresh.layout.util.DensityUtil;
import com.yiqi.news.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class SignSuccessDialog extends Dialog {


    private Context context;


    private LayoutInflater layoutInflater;

    public SignSuccessDialog(Context context) {
        super(context, R.style.ActionImmediatelyDialogStyle);
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        View view = layoutInflater.inflate(R.layout.dialog_success, null);
        ButterKnife.bind(this, view);
        setContentView(view);


        //获取当前Activity所在的窗体
        Window dialogWindow = getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;


        getWindow().getDecorView().setPadding(DensityUtil.dp2px(24), 0, DensityUtil.dp2px(24), 0);
        getWindow().setAttributes(layoutParams);

    }


    @OnClick({R.id.tv_dialog_close, R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_dialog_close:
            case R.id.btn_login:
                dismiss();
                break;
        }
    }
}
